import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from Base.PublicFunction import OpenBroswer
from selenium.webdriver.support.select import Select
from selenium import webdriver

class WoniuBossObj():
    def __init__(self):
        self.dr = OpenBroswer.openbrower()
        # self.dr = webdriver.Firefox()
        # self.dr.maximize_window()
        self.dr.get('http://10.10.10.171:8080/WoniuBoss4.0/login')
        self.dr.find_element_by_name('userName').send_keys('WNCD000')
        self.dr.find_element_by_name('userPass').send_keys('woniu123')
        self.dr.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/button').click()

    def findElement(self, locator):
        ele = WebDriverWait(self.dr, 10, 0.1).until(EC.presence_of_element_located(locator))
        return ele
    # def findElements(self,locator):
    #     eles= WebDriverWait(self.dr, 10, 0.1).until(EC.presence_of_all_elements_located(locator))
    #     return eles

    def close(self):
        self.dr.close()

    def get_humanmange(self): #人事管理-员工管理-新增员工信息
        locator = (By.XPATH, "/html/body/div[4]/div[2]/div[12]/div[1]/a")
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[4]/div[2]/div[12]/div[1]/a') #点击‘人事管理’
    def get_staffinfo(self):
        locator = (By.LINK_TEXT, "员工信息")
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_link_text('员工信息') #点击‘员工信息’
    def get_creatbutton(self):
        locator = (By.CLASS_NAME, "btn.btn-primary.btn-padding")
        eles = self.findElement(locator)
        return eles
        # return self.dr.find_elements_by_class_name('btn.btn-primary.btn-padding')

    def get_creatinfo(self,info):
        select_list = Select(self.dr.find_elements_by_name('emp.region_id')[1])
        return select_list.select_by_visible_text(info) #新增员工-区域

    def get_creatempment(self,empment):
        select_list = Select(self.dr.find_elements_by_name('emp.department_id')[1])
        return select_list.select_by_visible_text(empment) #新增员工-部门

    def get_position(self):
        locator = (By.NAME,"emp.position")
        ele= self.findElement(locator)
        return ele
        # return self.dr.find_elements_by_name('emp.position') #职位

    def get_name(self):
        locator = (By.NAME, "emp.employee_name")
        ele = self.findElements(locator)
        return ele
        # return self.dr.find_elements_by_name('emp.employee_name') #输入姓名

    def get_workid(self):
        locator = (By.NAME, "emp.work_id")
        ele = self.findElements(locator)
        return ele
        # return self.dr.find_elements_by_name('emp.work_id') #输入工号

    def get_saving(self):
        locator = (By.ID, "addEmpBtn")
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_id('addEmpBtn') #点击保存

    def get_determine(self):
        locator = (By.XPATH, "/html/body/div[16]/div/div/div[3]/button")
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[16]/div/div/div[3]/button') #点击确定

    def get_region(self,region):
        select_list = Select(self.dr.find_element_by_id('regionSel'))
        return select_list.select_by_visible_text(region) #页面查询-地区

    def get_dep(self,dep):
        select_list = Select(self.dr.find_element_by_class_name('sel-text.dept'))
        return select_list.select_by_visible_text(dep) #页面查询 -部门

    def get_status(self,status):
        select_list = Select(self.dr.find_element_by_class_name('emp_status.sel-text'))
        return select_list.select_by_visible_text(status) #页面查询-状态

    def get_staffname(self):
        locator = (By.XPATH, "/html/body/div[9]/div[2]/div[1]/input")
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_name('empName') #页面查询-姓名
        #self.dr.find_element_by_xpath('/html/body/div[9]/div[2]/div[1]/input')

    def get_clicks(self):
        locator = (By.CLASS_NAME, "btn.btn-info.btn-padding")
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_class_name('btn.btn-info.btn-padding') #点击查询

    def get_table(self):
        locator = (By.ID, "employee-table")
        ele = self.findElement(locator)
        return ele
        # tableobj = self.dr.find_element_by_id('employee-table')
        # tableobj = self.dr.find_element_by_class_name('table.table-hover.table-striped')
        # return tableobj



